package com.soft.demo4.app;

import java.time.Duration;
import java.time.LocalDateTime;

public class Payment {
    //inDayLightSavingOfStartTime为标志判断位，0为春季，1为秋季
    //inDayLightSavingOfEndTime，0为春季，1为秋季
    //返回时间差
    public long calculateTimeSpan(final LocalDateTime startTime,final Boolean inDayLightSavingOfStartTime, final LocalDateTime endTime, final Boolean inDayLightSavingOfEndTime) {
        Duration duration = Duration.between(startTime, endTime);
        long timeLength = 0;
        if (inDayLightSavingOfStartTime == inDayLightSavingOfEndTime) {
             timeLength =  duration.toMillis() / 1000;
        } else if (inDayLightSavingOfStartTime == false && inDayLightSavingOfEndTime == true) {
            timeLength =  duration.toMillis() / 1000 + 60 * 60;
        } else if (inDayLightSavingOfStartTime == true && inDayLightSavingOfEndTime == false) {
            timeLength =  duration.toMillis() / 1000 - 60 * 60;
        }


        return timeLength;
    }
   public String calculateFee(long timeLength) {
        if (timeLength > 0 && timeLength <= 60) {

           return String.valueOf(0.05);

       } else if (timeLength > 60 && timeLength < 1200) {
           if (timeLength % 60 == 0) {
               return String.valueOf((timeLength / 60) * 0.05);
           }
           return String.valueOf(((timeLength / 60) + 1) * 0.05);
           // if ( s >= 1200 && s < 108000)
       } else {
           if (timeLength % 60 == 0) {

               return String.valueOf(1 + ((timeLength - 1200) / 60) * 0.1);
           }
           return String.valueOf(1 + ((timeLength - 1200) / 60 + 1) * 0.1);
       }
   }

}
